<template>
  <div class="Purchase">
    <div class="head clear">
      <div class="btnTop clear">
        <GRButton class="goodsTopL" :btnText="btnText" />
      </div>
    </div>
    <div class="commodityContent" style="overflow: initial;">
      <TableList :tableData="tableData" :titleList="titleList" :linklist="linklist" :selWidth="selWidth"
        :btnState="btnState" :limit="limit" :url="url" @getCheck="getCheck" @reshow="dataShow" />
    </div>
    <Paging class="footer" :total="total" @getPage="getPage" @getLimit="getLimit" />
  </div>
</template>

<script>
  import GRButton from '../../../components/GoodsComponent/GoodsRouterButton.vue';
  import TableList from "../../../components/List.vue";
  import Paging from '../../../components/Paging.vue';
  import { purchaseList } from '../../../http/apis/goodsApi/purchase.js'
  import { mapState, mapMutations, mapActions } from 'vuex'
  // 时间戳的转换
  import { timeFormat } from "../../../utils/utils";
  export default {
    components: {
      GRButton,
      TableList,
      Paging
    },
    data() {
      return {
        checkVal: [],
        // 表格数据
        tableData: [],
        // 默认每页总数
        limit: 3,
        // 当前页数
        page: 1,
      }
    },
    computed: {
      ...mapState('goodsStore', ['Ftype', 'btnText', 'url', 'type', 'linklist', 'titleList', 'selWidth', 'state', 'isCheck', 'total', 'btnState']),
    },
    methods: {
      ...mapMutations('goodsStore', ['Purchaselist', 'upState']),
      ...mapActions('goodsStore', ['GetCounts']),
      // 获取选择对象
      getCheck(val) {
        this.checkVal = val;
      },
      // 翻页
      getPage(val) {
        this.page = val;
        this.dataShow();
      },
      // 修改每页显示长度
      getLimit(val) {
        this.limit = val;
        this.dataShow();
      },
      // 渲染数据转格式
      showDataType(datas) {
        let listArr = datas.filter((item) => {
          item.goods_cost = item.goods_cost / 1000;
          item.goods_price = item.goods_price / 1000;
          item.pur_price = item.pur_price / 1000;
          item.discount = item.discount / 1000;
          item.pur_numb_price = item.pur_numb_price / 1000;
          item.pur_freight = item.pur_freight / 1000;
          item.pur_time = timeFormat(item.pur_time)
          return item;
        });
        return listArr;
      },
      // 页面渲染
      dataShow() {
        this.GetCounts({ database: this.type })
        purchaseList({
          currentPage: this.page,
          pageSize: this.limit,
        })
          .then((res) => {
            console.log('采购列表成功请求:', res);
            if (res.data.code == '200') {
              this.tableData = this.showDataType(res.data.data)
            }
          })
          .catch((err) => {
            console.log('请求失败', err)
          });
      },
    },
    created() {
      this.Purchaselist();
      this.GetCounts({ database: this.type })
      this.dataShow()
    },
  }
</script>

<style>

</style>